package com.low.controller;

import java.io.FileNotFoundException;

import java.util.List;
import java.util.Locale;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.low.entity.Psysacount;
import com.low.service.IPsysacount;




/**
 * 注解驱动的控制器 在此控制器接收来自DispatcherServlet的
 */
@Controller
public class HomeController {
	@Resource
	IPsysacount ipsysacount;
	private static final Logger logger = LoggerFactory
			.getLogger(HomeController.class);

	/**
	 * Simply selects the home view to render by returning its name.
	 * 
	 * @throws FileNotFoundException
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model) throws FileNotFoundException {
		logger.info("Welcome home! The client locale is {}.", locale);
		return "";
	}

	/**
	 * 跳转到注册
	 * 
	 * @return
	 */
	@RequestMapping(value = "/regist", method = RequestMethod.GET)
	public String removeUser() {
		return "regist";
	}

	@RequestMapping(value = "/sysacount", method = RequestMethod.GET)
	public String skipSysacount() {
		return "sysacount/sysacountinfo";
	}

	/**
	 * 缓存body 的样式
	 * 
	 * @param request
	 * @param bodyclass
	 */
	@RequestMapping(value = "/bodyclass", method = RequestMethod.POST)
	public void bodyStyle(HttpServletRequest request, String bodyclass) {
		request.getSession().setAttribute("bodyclass", bodyclass);
	}

	@RequestMapping(value = "/notice", method = RequestMethod.GET)
	public void notice(Model model, HttpServletRequest request) {
		ServletContext application = request.getSession().getServletContext();
		String mess = (String) application.getAttribute("mess");
		if (mess == null) {
			application.setAttribute("mess", "1");
		} else {
			Integer notice = Integer.parseInt(mess);
			notice++;
			application.setAttribute("mess", notice + "");
		}

	}

	@RequestMapping(value = "/canclenotice", method = RequestMethod.GET)
	public void canclenotice(Model model, HttpServletRequest request) {
		ServletContext application = request.getSession().getServletContext();
		Integer notice = Integer.parseInt((String) application
				.getAttribute("mess"));
		if (notice != null) {
			notice--;
			if (notice < 0) {
				notice = 0;
			}
			application.setAttribute("mess", notice + "");
		} else {
			application.setAttribute("mess", 0 + "");
		}
	}

	//不要删除 一个模仿的心包
	@RequestMapping(value = "/noticeupdate", method = RequestMethod.GET)
	public void notice(HttpServletRequest request, HttpServletResponse response) {
		
	}
	
	@RequestMapping("/downsql")
	public String skipDownsql(){
		List<Psysacount> pList =ipsysacount.findSysacount();
	System.out.println("dd"+pList.size());
		return "down";
	}
	
}
